import request from '@/utils/request';
import config from '@/env/config';
import { IResume } from '@/types';
import { ICommodityReq } from '@/types/params';

/**
 * 根据条件查询阿姨简历列表
 * @returns string
 */
export function getResumeList(params: ICommodityReq): Promise<IResume[]> {
  return request({
    method: 'get',
    params,
    url: `${config.SERVICE_API}api/commodity/list`,
  });
}

/**
 * 获取推荐列表
 * @returns string
 */
export function getRecommendList(params: { cityCode: string }): Promise<IResume[]> {
  return request({
    method: 'get',
    params,
    url: `${config.SERVICE_API}api/commodity/recommend`,
  });
}

/**
 * 获取简历详情
 * @returns string
 */
export function getCommodityInfo(params: { id: string; userPhone: string }): Promise<IResume> {
  return request({
    method: 'get',
    params,
    url: `${config.SERVICE_API}api/commodity/info`,
  }).then((v: IResume) => {
    v.certificateList = v.certificate?.split(',') || [];
    return v;
  });
}

/**
 * 收藏取消收藏简历
 * @returns boolean
 *
 */
export function resumeCollect(data): Promise<number> {
  return request({
    method: 'post',
    data,
    url: `${config.SERVICE_API}api/commodity/collect`,
  });
}

/**
 * 查询收藏情况
 * @returns boolean
 *
 */
export function queryCollect(params): Promise<number> {
  return request({
    method: 'get',
    params,
    url: `${config.SERVICE_API}api/commodity/queryCollect`,
    isTransformResponse: true,
  }).then((res) => res.data);
}

/**
 * 查询所有收藏记录
 */
export function queryUserCollect(params): Promise<IResume[]> {
  return request({
    method: 'get',
    params,
    url: `${config.SERVICE_API}api/commodity/queryUserCollect`,
  });
}
